// vim: foldmethod=marker : foldmarker=<<<,>>>
/*
 File: steward.h
 Product: <product>
 Creating date: 08/12/2006 13:12
 Remark: 
*/
#ifndef soddy_heap_stewardH
#define soddy_heap_stewardH

#include "lite/lite.h"
#include "spool/datum.h"

typedef i_t (* heap_steward_askFor_p)(v_p, i_t size, spool_datum_p datum);

typedef struct _heap_steward_law_t_ {
 i_t drift;
 heap_steward_askFor_p askFor;
 } heap_steward_law_t;
typedef heap_steward_law_t * heap_steward_law_p;
typedef heap_steward_law_p * heap_steward_law_pp;

typedef struct _heap_steward_t_ { heap_steward_law_p tag; } heap_steward_t;
typedef heap_steward_t * heap_steward_p; 
typedef heap_steward_p * heap_steward_pp;

#define unpack \
 heap_steward_law_p law=(heap_steward_law_p)_this->tag;\
 v_p engine=(v_p)(((i1_p)_this)+law->drift)

inline_q v_p getEngine__heap_steward(heap_steward_p _this) 
 { unpack; return engine; };

inline_q i_t askFor__heap_steward(heap_steward_p _this, i_t size, spool_datum_p datum) {
 unpack;
 return law->askFor(engine,size,datum);
 };

#undef unpack

inline_q v_p claim__heap_steward(heap_steward_p _this, i_t rawSize) {
 spool_datum_t d;
 zero__spool_datum(&d);
 return askFor__heap_steward(_this,rawSize,&d)?d.raw:NULL;
 };

inline_q v_t retract__heap_steward(heap_steward_p _this, R_p(raw)) {
 spool_datum_t d; 
 putRaw__spool_datum(&d,RAW__d(raw));
 askFor__heap_steward(_this,0,&d);
 };

#endif

